package com.idata.model.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

import javax.print.DocFlavor.STRING;
import java.util.HashMap;
import java.util.Map;

@AllArgsConstructor
@Getter
public enum GraphAnalysisNodeTypeEnum {
    PEOPLE(1, "people"),
    DISPUTE(2, "dispute"),
    ;

    private final int code;

    private final String desc;


    private static final Map<Integer, GraphAnalysisNodeTypeEnum> VALUES_FOR_CODE = new HashMap<>();

    private static final Map<String, GraphAnalysisNodeTypeEnum> VALUES_FOR_DESC = new HashMap<>();

    static {
        for (GraphAnalysisNodeTypeEnum graphAnalysisNodeTypeEnum : GraphAnalysisNodeTypeEnum.values()) {
            VALUES_FOR_CODE.put(graphAnalysisNodeTypeEnum.getCode(), graphAnalysisNodeTypeEnum);
            VALUES_FOR_DESC.put(graphAnalysisNodeTypeEnum.getDesc(), graphAnalysisNodeTypeEnum);
        }
    }

    @Nullable
    public static GraphAnalysisNodeTypeEnum fromCode(Integer code) {
        if (code == null) {
            return null;
        }
        return VALUES_FOR_CODE.get(code);
    }

    @Nullable
    public static GraphAnalysisNodeTypeEnum fromDesc(String desc) {
        if (desc == null) {
            return null;
        }
        return VALUES_FOR_DESC.get(desc);
    }

    @Nullable
    public static String getDescFromCode(Integer code) {
        GraphAnalysisNodeTypeEnum graphAnalysisNodeTypeEnum = fromCode(code);
        if (graphAnalysisNodeTypeEnum == null) {
            return null;
        }
        return graphAnalysisNodeTypeEnum.getDesc();
    }
}
